package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import util.MyHttpUtil;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MyController {
    //service.....

    //假设现在从数据库读取数数据
    @RequestMapping("stuList.html")
    @ResponseBody
    public Map<String, Object> get() {
        //模拟数据库读取出的数据
        List<Student> students = new ArrayList<>();
        students.add(new Student("张三", 1));
        students.add(new Student("张三", 2));
        students.add(new Student("张三", 3));
        students.add(new Student("张三", 4));
        students.add(new Student("张三", 5));
        students.add(new Student("张三", 6));
        Map<String, Object> res = new HashMap<>();
        res.put("status", "200");
        res.put("message", "success");
        res.put("result", students);
        return res;
    }

    @RequestMapping("send.html")
    public String send(String phone) throws Exception {
        String url = "http://106.ihuyi.com/webservice/sms.php?method=Submit&";
        String param = "mobile="+phone+"&account=C58981726&password=73daf62d565ce1ed27c4cbe81044dd2f&content=您的验证码是：1234。请不要把验证码泄露给其他人。";
        String res = MyHttpUtil.sendGet(url, param);
        System.out.println(res);
        return "index.jsp";
    }
}
